/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on Jul 5, 2011, 8:49:18 PM
 */
package main;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UnsupportedLookAndFeelException;
import panels.WelcomePanel;
import panels.Dashboard;
import panels.LoginPanel;
import panels.RegisterPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.UIManager;
import obj.Page;

/**
 *
 * @author jm1156, nknowles
 */
public class MainFrame extends javax.swing.JFrame {

  private static MainFrame instance;

  /** Creates new form MainFrame */
  private MainFrame() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException ex) {
      Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
      Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedLookAndFeelException ex) {
      Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
    initComponents();

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((dim.width - this.getSize().width) / 2, (dim.height - this.getSize().height) / 2);

    Page page = new Page();
    page.setTitle("Welcome");
    setPanel(page);
  }

  public static MainFrame getInstance() {
    if (instance == null) {
      instance = new MainFrame();
    }
    return instance;
  }

  public void setPanel(Page page) {
    System.out.println("Changing page: " + page.getTitle());
    //get rid of all elements within the panel
    m_pnlMainPanel.removeAll();
    if (page.getTitle() == "Login") {
      m_pnlMainPanel.add(new LoginPanel(), BorderLayout.NORTH);
    } else if (page.getTitle() == "Register") {
      m_pnlMainPanel.add(new RegisterPanel(), BorderLayout.NORTH);
    } else if (page.getTitle() == "Welcome") {
      m_pnlMainPanel.add(new WelcomePanel(), BorderLayout.CENTER);
    } else if (page.getTitle() == "Dashboard") {
      m_pnlMainPanel.add(new Dashboard(), BorderLayout.CENTER);
    }
    m_pnlMainPanel.validate();

    m_pnlMainPanel.repaint();

    this.repaint();
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
  //*/
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    m_pnlMainPanel = new javax.swing.JPanel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Electronic Medical Information System");
    setBounds(new java.awt.Rectangle(150, 150, 0, 0));
    setMinimumSize(new java.awt.Dimension(800, 600));
    setName("mainFrame"); // NOI18N
    setResizable(false);

    m_pnlMainPanel.setBackground(new java.awt.Color(220, 220, 210));
    m_pnlMainPanel.setMaximumSize(new java.awt.Dimension(1900, 1000));
    m_pnlMainPanel.setMinimumSize(new java.awt.Dimension(800, 600));
    m_pnlMainPanel.setName("m_pnlMainPanel"); // NOI18N
    m_pnlMainPanel.setPreferredSize(new java.awt.Dimension(800, 600));
    m_pnlMainPanel.setLayout(new java.awt.BorderLayout());
    getContentPane().add(m_pnlMainPanel, java.awt.BorderLayout.CENTER);

    pack();
  }// </editor-fold>//GEN-END:initComponents

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    MainFrame mainFrame = MainFrame.getInstance();
    mainFrame.setVisible(true);
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel m_pnlMainPanel;
  // End of variables declaration//GEN-END:variables
}
